clear;clc
syms s L R 
syms Kp Ki
syms wn zeta

assume(L>0)
assume(R>0)
assume(Kp>0)
assume(Ki>0)
assume(wn>0)
assume(zeta>0)

%% param
R = 0.671
L = 0.716e-3
s = tf('s')
Kp = 10
Ki = 1000

%% sys
plant = 1/(L*s+R);
controller = Kp + Ki/s;
sys_close = (controller * plant) / (1 + controller * plant)

% sys_close = collect(sys_close, s)

wn = sqrt(Ki/L)
zeta = (Kp + R)/L/2/wn

%%指标
wr = wn*sqrt(1-2*zeta^2)
Mr = 1/sqrt(2*zeta*(1-zeta^2))
wc = sqrt(2)*wr
wb = [wn*sqrt(1+sqrt(4*zeta^4-4*zeta^2+2)-2*zeta^2), ...
      wn*sqrt(1-sqrt(4*zeta^4-4*zeta^2+2)-2*zeta^2)]

%% bode
bode(sys_close)
%%
step(sys_close)